<?php

namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        // require_once admin_path() . '/Extensions/Validators.php';
        
        if (env('APP_DEBUG')) {
            DB::listen(function ($sql) {
                $sql_arr = json_decode(json_encode($sql), true);
                try {
                    logger('sql: '.vsprintf(str_replace('?', '%s', $sql->sql), $sql->bindings));
                } catch (\Exception $e) {
                    Log::error('DB:listen error: '.$e->getMessage(), $sql_arr);
                }
            });
        }
    }
    
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
